/*******************************************************************************
* Project: QSAR(Cute Software Architecture)
*
* Copyright: Copyright(C) 2024 by YuetingBen, All Rights Reserved
*
* File name: CanDrvType.h
*
* Brief: ;
*
* Author: Yueting.Ben
*
* Module: CanDrv
*
*******************************************************************************/

#ifndef CANDRVTYPE_H
#define CANDRVTYPE_H

/** HEADER FILES **/
#include "PlatformCfg.h" 
#include "ComStackType.h"


/** MACRO DEFINITION **/


/** TYPEDEF DEFINITION **/
typedef uint32 Can_IdType;

typedef uint8 Can_HwHandleType;
#define CanConf_HwHandle_Can_0 ((Can_HwHandleType)0u)
#define CanConf_HwHandle_Can_Max ((Can_HwHandleType)1u)

typedef struct
{
  Can_IdType CanId;
  Can_HwHandleType Hoh;
  uint8 ControllerId;
}Can_HwType;


typedef struct
{
  PduIdType swPduHandle;
  uint8 length;
  Can_IdType id;
  uint8* sdu;
}Can_PduType;

typedef uint8 Can_ControllerStateType;
#define AN_CS_UNINIT ((Can_ControllerStateType)0x00)  /* CAN controller state UNINIT */
#define CAN_CS_STARTED ((Can_ControllerStateType)0x01)  /* CAN controller state STARTED */
#define CAN_CS_STOPPED ((Can_ControllerStateType)0x02)  /* CAN controller state STOPPED */
#define CAN_CS_SLEEP ((Can_ControllerStateType)0x03)  /* CAN controller state SLEEP */

/* Variables of this type are used to express time stamps based on relative time.
Value range: * Seconds: 0 .. 4.294.967.295 s (circa 136 years) * Nanoseconds: 0 .. 999.999.999 ns */
typedef struct
{
    uint32 nanoseconds;
    uint32 seconds;
}Can_TimeStampType;

typedef uint8 Can_ErrorStateType;
/* The CAN controller takes fully part in communication */
#define CAN_ERRORSTATE_ACTIVE ((Can_ErrorStateType)0x00)
/* The CAN controller takes part in communication, but does not send active error frames */
#define CAN_ERRORSTATE_PASSIVE ((Can_ErrorStateType)0x01)
/* The CAN controller does not take part in communication */
#define CAN_ERRORSTATE_BUSOFF ((Can_ErrorStateType)0x02)

typedef uint8 Can_ErrorType;
/* A 0 was transmitted and a 1 was read back */
#define CAN_ERROR_BIT_MONITORING1 ((Can_ErrorType)0x01)
/* A 1 was transmitted and a 0 was read back */
#define CAN_ERROR_BIT_MONITORING0 ((Can_ErrorType)0x02)
/* The HW reports a CAN bit error but cannot report distinguish between CAN_ERROR_BIT_MONITORING1 and CAN_ERROR_BIT_MONITORING0 */
#define CAN_ERROR_BIT ((Can_ErrorType)0x03)
/* Acknowledgement check failed */
#define CAN_ERROR_CHECK_ACK_FAILED ((Can_ErrorType)0x04)
/* Acknowledgement delimiter check failed */
#define CAN_ERROR_ACK_DELIMITER ((Can_ErrorType)0x05)
/* The sender lost in arbitration */
#define CAN_ERROR_ARBITRATION_LOST ((Can_ErrorType)0x06)
/* CAN overload detected via an overload frame. Indicates that the receive buffers of a receiver are full. */
#define CAN_ERROR_OVERLOAD ((Can_ErrorType)0x07)
/* Violations of the fixed frame format */
#define CAN_ERROR_CHECK_FORM_FAILED ((Can_ErrorType)0x08)
/* Stuffing bits not as expected */
#define CAN_ERROR_CHECK_STUFFING_FAILED ((Can_ErrorType)0x09)
/* CRC failed */
#define CAN_ERROR_CHECK_CRC_FAILED ((Can_ErrorType)0x0A)
/* Bus lock (Bus is stuck to dominant level) */
#define CAN_ERROR_BUS_LOCK ((Can_ErrorType)0x0B)


#endif

